﻿using DRHotel_v1.Classes;
using DRHotel_v1.Classes.DBManagers;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DRHotel_v1.HousekeepingAndStaffMngmt
{
    public partial class StaffManagementRetrievedFeedback : Form
    {
        public StaffManagementRetrievedFeedback(string Type, string Value)
        {
            InitializeComponent();

            //Defining what the user search by and get the results 
            if (Type.Equals("Staff ID"))
            {
                int value2 = Convert.ToInt32(Value);
                ArrayList staffList = HousekeepingDBManager.GetStaffListByStaffID(value2);

                int counter = 0;
                foreach (Staff staff in staffList)
                {
                    this.dgvResult.Rows.Add(new DataGridViewRowCollection(this.dgvResult));
                    this.dgvResult.Rows[counter].SetValues(staff.staffID, staff.firstName, staff.lastName, staff.email, staff.address, staff.dob.Date, gender, staff.nationality, staff.phoneNo, staff.staffType, staff.bankNo);
                    counter++;
                }
            }
            else if (Type.Equals("Staff Name"))
            {
                string[] words = Value.Split(' ');
                string firstName = words[0];
                string lastName = words[1];

                ArrayList staffList = HousekeepingDBManager.GetStaffListByStaffName(firstName, lastName);

                int counter = 0;
                foreach (Staff staff in staffList)
                {
                    string gender = "";
                    if (staff.gender == true)
                    {
                        gender = "Male";
                    }
                    else if (staff.gender == false)
                    {
                        gender = "Female";
                    }
                    this.dgvResult.Rows.Add(new DataGridViewRowCollection(this.dgvResult));
                    this.dgvResult.Rows[counter].SetValues(staff.staffID, staff.firstName, staff.lastName, staff.email, staff.address, staff.dob.Date, gender, staff.nationality, staff.phoneNo, staff.staffType, staff.bankNo);
                    counter++;
                }
            }
            else if (Type.Equals("Gender"))
            {
                ArrayList staffList = HousekeepingDBManager.GetStaffListByGender(Value);

                int counter = 0;
                foreach (Staff staff in staffList)
                {
                    string gender = "";
                    if (staff.gender == true)
                    {
                        gender = "Male";
                    }
                    else if (staff.gender == false)
                    {
                        gender = "Female";
                    }
                    this.dgvResult.Rows.Add(new DataGridViewRowCollection(this.dgvResult));
                    this.dgvResult.Rows[counter].SetValues(staff.staffID, staff.firstName, staff.lastName, staff.email, staff.address, staff.dob.Date, gender, staff.nationality, staff.phoneNo, staff.staffType, staff.bankNo);
                    counter++;
                }
            }
            else if (Type.Equals("Staff Type"))
            {
                ArrayList staffList = HousekeepingDBManager.GetStaffListByType(Value);

                int counter = 0;
                foreach (Staff staff in staffList)
                {
                    string gender = "";
                    if (staff.gender == true)
                    {
                        gender = "Male";
                    }
                    else if (staff.gender == false)
                    {
                        gender = "Female";
                    }
                    this.dgvResult.Rows.Add(new DataGridViewRowCollection(this.dgvResult));
                    this.dgvResult.Rows[counter].SetValues(staff.staffID, staff.firstName, staff.lastName, staff.email, staff.address, staff.dob.Date, gender, staff.nationality, staff.phoneNo, staff.staffType, staff.bankNo);
                    counter++;
                }
            }
            else if (Type.Equals("All"))
            {
                ArrayList staffList = HousekeepingDBManager.GetAllStaffList();

                int counter = 0;
                foreach (Staff staff in staffList)
                {
                    string gender = "";
                    if (staff.gender == true)
                    {
                        gender = "Male";
                    }
                    else if (staff.gender == false)
                    {
                        gender = "Female";
                    }
                    this.dgvResult.Rows.Add(new DataGridViewRowCollection(this.dgvResult));
                    this.dgvResult.Rows[counter].SetValues(staff.staffID, staff.firstName, staff.lastName, staff.email, staff.address, staff.dob.Date, gender, staff.nationality, staff.phoneNo, staff.staffType, staff.bankNo);
                    counter++;
                }
            }

        }
    }
}
